package com.fc.nacosdemo.controller;

import com.fc.nacosdemo.bpoint.annotation.BPoint;
import com.fc.nacosdemo.bpoint.annotation.EBusinessOPT;
import com.fc.nacosdemo.listener.pojo.User;
import com.fc.nacosdemo.nacos.NacosConfigLocalCatch;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RefreshScope// 开启动态刷新
public class TestController {

    private Logger logger = LoggerFactory.getLogger(TestController.class);

    @Value("${my.name}")
    private String name;

    @Value("${my.age}")
    private Integer age;

    @Value("${abc}")
    private String abc;

    @Value("${common.key1}")
    private String commonKey1;

    @RequestMapping("/test")
    public String test() {
        logger.info("-------------test---------------");
        logger.info("name  =  {} ,age ={} , abc = {} , commonKey1 = {}", name, age, abc, commonKey1);
        return "Hello ~ ";
    }

    @Autowired
    private NacosConfigLocalCatch nacosConfigLocalCatch;

    @RequestMapping("/test2")
    @BPoint(key = EBusinessOPT.TEST, valueNames = {"#user.name","#user.age","#user.phone","#testabc"})
    public String test2(User user,String testabc) {
        logger.info("-------------test2---------------");
        String testText = nacosConfigLocalCatch.get("testText", String.class);
        List testJson1 = nacosConfigLocalCatch.get("testJson1", List.class);
        User testJson2 = nacosConfigLocalCatch.get("testJson2", User.class);
        Integer testInteger = nacosConfigLocalCatch.get("testInteger", Integer.class);
        return testText+" , "+testJson1+" , "+testJson2+" , "+testInteger;
    }

}
